package csvIO;

import java.util.LinkedList;
import java.util.List;

public class CsvObject {
	
	private List<CsvRow> rows;
	private String[] headers;
	
	public CsvObject(){
		rows = new LinkedList<CsvRow>();
	}
	
	public boolean isEmpty(){
		return !hasHeaders() && !hasRows();
	}
	
	public boolean hasHeaders(){
		return headers != null;
	}
	
	public boolean hasRows(){
		return rows.size() > 0;
	}
	
	public int getRowsCount(){
		return rows.size();
	}
	
	public int getRowLength() {
		if(hasHeaders())
			return headers.length;
		else if(hasRows()){
			return rows.get(0).getLength();
		}
		
		throw new IllegalStateException("If this csv object has no headers, it has to have at least one row, to determine row length");
	}

	public String[] getHeaders() {
		return headers;
	}

	public void setHeaders(String[] headers) {
		this.headers = headers;
	}
	
	public String getHeader(int index){
		return headers[index];
	}

	public List<CsvRow> getRows(){
		return rows;
	}
	
	public CsvRow getRow(int index){
		return rows.get(index);
	}
	
	public void setRows(List<CsvRow> rows){
		this.rows = rows;
	}
	
	public void setRow(int index, CsvRow row){
		rows.set(index, row);
	}
	
	public boolean addRow(CsvRow row){
		return rows.add(row);
	}
	
	public boolean removeRow(CsvRow row){
		return rows.remove(row);
	}
}
